package com.qianfeng.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.dto.Page;
import com.qianfeng.entity.Employee;
import com.qianfeng.entity.Role;
import com.qianfeng.mapper.EmployeeMapper;
import com.qianfeng.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Transactional
@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public void addEmployee(Employee employee) {
        employeeMapper.addEmployee(employee);
    }

    @Override
    public void deleteEmployee(Integer empId) {
        employeeMapper.deleteEmployee(empId);
    }

    @Override
    public void updateEmployee(Employee employee) {
        employeeMapper.updateEmployee(employee);
    }

    @Override
    public List<Employee> getListByEmpId(Integer empId) {

        List<Employee> list = employeeMapper.getListByEmpId(empId);
        return list;
    }

    @Override
    public List<Employee> getEmployeeList() {
        List<Employee> employeeList = employeeMapper.getEmployeeList();
        return employeeList;
    }

    @Override
    public Page getEmployeePage(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<Employee> employeeList = employeeMapper.getEmployeeList();
        Page page = new Page();
        PageInfo<Employee> pageInfo = new PageInfo<>(employeeList);
        page.setCount(pageInfo.getTotal());
        page.setObj(pageInfo.getList());
        page.setPages(pageInfo.getPages());
        return page;
    }
}
